package 设计模式.创建型.单例模式.几种单例的实现;

import java.util.concurrent.atomic.AtomicLong;

public class IdGeneratorInnerStaticClass {
    private AtomicLong id = new AtomicLong(0);
    private IdGeneratorInnerStaticClass() {}

    private static class SingletonHolder{
        private static final IdGeneratorInnerStaticClass instance = new IdGeneratorInnerStaticClass();
    }

    public static IdGeneratorInnerStaticClass getInstance() {
        return SingletonHolder.instance;
    }

    public long getId() {
        return id.incrementAndGet();
    }
}
